/*
 * @Author: PC9527\Jack sophia2152@qq.com
 * @Date: 2023-08-07 15:04:04
 * @LastEditors: PC9527\Jack sophia2152@qq.com
 * @LastEditTime: 2023-08-10 15:32:39
 * @Description:
 */
import {
  RolePageParams,
  RolePageListGetResultModel,
  RoleListGetResultModel,
  RoleParams,
  RoleSelectListGetResultModel,
} from './model/roleModel';
import { defHttp } from '/@/utils/http/axios';

enum Api {
  RolePageList = '/system/role/list',
  CreateRole = '/system/role/create',
  RoleInfo = '/system/role/read',
  UpdateRole = '/system/role/create',
  DeleteRole = '/system/role/delete',
  SetRoleStatus = '/system/role/set_status',
  RoleMenus = '/system/role/role_menus',
  RoleSelectList = '/system/role/search_roles',
}

/**
 * 角色列表
 * @param params
 * @returns
 */
export const getRoleListPage = (params: RolePageParams) =>
  defHttp.get<RolePageListGetResultModel>({ url: Api.RolePageList, params });

/**
 * 添加角色
 * @param id
 * @param params
 * @returns
 */
export const createRole = (id: number, params: RoleParams) =>
  defHttp.post({ url: `${Api.CreateRole}/${id}`, params });

/**
 * 角色详情
 * @param id
 * @param params
 * @returns
 */
export const getRoleInfo = (id: number) =>
  defHttp.get<RoleInfoGetResultModel>({ url: `${Api.RoleInfo}/${id}` });

/**
 * 修改角色
 * @param id
 * @param params
 * @returns
 */
export const updateRole = (id: number, params: RoleParams) =>
  defHttp.post({ url: `${Api.UpdateRole}/${id}`, params });

/**
 * 删除角色
 * @param id
 * @returns
 */
export const delRole = (id: number) => defHttp.delete({ url: `${Api.DeleteRole}/${id}` });

/**
 * 设置角色状态
 * @param id
 * @param status
 * @returns
 */
export const setRoleStatus = (id: string, status: number) =>
  defHttp.put({ url: `${Api.SetRoleStatus}/${id}/${status}` });

/**
 * 查询权限列表
 * @returns
 */
export const getRoleMenus = () => defHttp.get<RoleListGetResultModel>({ url: Api.RoleMenus });

/**
 * 下拉列表
 * @returns
 */
export const getRoleSelectList = () =>
  defHttp.get<RoleSelectListGetResultModel>({ url: Api.RoleSelectList });
